package com.authority.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.authority.entry.AuthRoleTypeDO;
import com.authority.query.AuthRoleTypeQuery;
import com.authority.service.AuthRoleTypeService;

/**
 * 角色类型管理
 * 
 * @author wb-leizhendong
 *
 */
@Controller
@RequestMapping(value = "/auth/roleTypeManager")
public class RoleTypeManager extends BaseManager {

	@Resource
	AuthRoleTypeService authRoleTypeService;

	/**
	 * 角色类型列表
	 * 
	 * @param name
	 *            名称
	 * @param sysId
	 *            系统id
	 * @param index
	 *            页数
	 * @return
	 */
	
	@RequestMapping(value = "/queryRoleType.json")
	@ResponseBody
	public Object doQueryRoleType(String name,Long sysId,int index) {

		try {
			checkParams(sysId);

			AuthRoleTypeQuery query = new AuthRoleTypeQuery();
			query.setName(name);
			query.setSysId(sysId);
			query.setIndex(index);
			return success(authRoleTypeService.getAuthRoleTypeList(query));
		} catch (Exception e) {
			return fail(e);
		}

	}

	/**
	 * 根据id查询角色类型信息
	 * 
	 * @param id
	 * @return
	 */
	
	@RequestMapping(value = "/queryRoleTypeById.json")
	@ResponseBody
	public Object doQueryRoleTypeById(Long id) {

		try {
			checkParams(id);

			return success(authRoleTypeService.getAuthRoleTypeById(id));
		} catch (Exception e) {
			return fail(e);
		}

	}

	/**
	 * 新增角色类型
	 * 
	 * @param name
	 *            名称
	 * @param remark
	 *            备注
	 * @param sysId
	 *            系统id
	 * @return
	 */
	
	@RequestMapping(value = "/saveRoleType.json")
	@ResponseBody
	public Object doSaveRoleType(String name,String remark,Long sysId) {

		try {
			checkParams(name, sysId);

			AuthRoleTypeDO db = new AuthRoleTypeDO();
			db.setName(name);
			db.setRemark(remark);
			db.setSysId(sysId);
			db.setOperatorId(getUserId());
			return success(authRoleTypeService.saveRoleType(db));
		} catch (Exception e) {
			return fail(e.getMessage());
		}

	}

	/**
	 * 更新角色类型信息
	 * 
	 * @param id
	 * @param name
	 * @param remark
	 * @return
	 */
	
	@RequestMapping(value = "/updateRoleType.json")
	@ResponseBody
	public Object doUpdateRoleType(Long id,String name, String remark) {

		try {
			checkParams(id);

			AuthRoleTypeDO db = authRoleTypeService.getAuthRoleTypeById(id);
			db.setName(name);
			db.setRemark(remark);
			db.setOperatorId(getUserId());
			return success(authRoleTypeService.modifyAuthRoleType(db));
		} catch (Exception e) {
			return fail(e.getMessage());
		}

	}

}
